package cn.cvs.service;

import cn.cvs.dao.SysUserMapper;
import cn.cvs.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService{
    @Autowired
    private SysUserMapper mapper;
    @Override
    public SysUser login(String account, String pwd) {
        SysUser user = mapper.selectByAccountAndPwd(account);
        if (user == null){
            return null;
        }
        if (!user.getPassword().equals(pwd)){
            return null;
        }
        return user;
    }

    @Override
    public List<SysUser> queryList(String realName,int roleId,int pageIndex,int pageSize) {
        int startIndex = (pageIndex - 1) * pageSize;
        return mapper.selectSysUserListBySysUser(realName,roleId,startIndex,pageSize);
    }

    @Override
    public int getListSize(String realName, int roleId) {
        return mapper.listSize(realName,roleId);
    }

    @Override
    public boolean add(SysUser user){
        return mapper.insertSysUser(user) > 0;
    }

    @Override
    public SysUser selectSysUser(int id) {
        return mapper.selectSysUserById(id);
    }

    @Override
    public Boolean modify(SysUser user) {
        return mapper.updateSysUser(user) > 0;
    }

    @Override
    public Boolean del(int id) {
        return mapper.deleteSysUser(id) > 0;
    }

    @Override
    public Boolean validateAccount(String account) {
        SysUser user = mapper.selectByAccountAndPwd(account);
        if (user == null){
            return true;
        }
        return false;
    }
}
